﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualBasic.FileIO;

namespace GoldenTuney.PCX
{
    public class PCWHelper
    {
        // Methods
        public garmin_PWXWorkout LoadPCWWorkoutFromTrainingPeaksCSVFile(garmin_PWXAthlete athlete, garmin_PWXDevice device)
        {
            garmin_PWXWorkout workout = new garmin_PWXWorkout();
            string filename = @"C:\temp\Chris_Tune_9_3_2009.csv";
            string delimiter = ",";
            using (TextFieldParser parser = new TextFieldParser(filename))
            {
                parser.SetDelimiters(new string[] { delimiter });
                parser.ReadFields();
                while (!parser.EndOfData)
                {
                    decimal Torq=0;
                    string[] fields = parser.ReadFields();
                    decimal Minutes = Convert.ToDecimal(fields[0]);
                    if (!string.IsNullOrEmpty(fields[1]))
                    {
                        Torq = Convert.ToDecimal(fields[1]);
                    }
                    if (!string.IsNullOrEmpty(fields[2]))
                    {
                        decimal Kmh = Convert.ToDecimal(fields[2]);
                    }
                    if (!string.IsNullOrEmpty(fields[3]))
                    {
                        decimal Watts = Convert.ToDecimal(fields[3]);
                    }
                    if (!string.IsNullOrEmpty(fields[4]))
                    {
                        decimal Km = Convert.ToDecimal(fields[4]);
                    }
                    if (!string.IsNullOrEmpty(fields[5]))
                    {
                        decimal Cadence = Convert.ToDecimal(fields[5]);
                    }
                    if (!string.IsNullOrEmpty(fields[6]))
                    {
                        decimal Hrate = Convert.ToDecimal(fields[6]);
                    }
                    if (!string.IsNullOrEmpty(fields[7]))
                    {
                        decimal ID = Convert.ToDecimal(fields[7]);
                    }
                    garmin_PWXSummaryData seg = new garmin_PWXSummaryData();
                    seg.Torquemma = new garmin_PWXMinMaxAvg();
                    seg.Torquemma.Min = Convert.ToDouble(Torq);
                    seg.Torquemma.Max = Convert.ToDouble(Torq);
                    seg.Torquemma.Avg = Convert.ToDouble(Torq);
                    workout.PWXSegments.Add(seg);
                }
            }
            return workout;
        }
    }


}
